<template>
  <div style="padding: 60px">
    <el-button type="primary" @click="choose" size="large">奖学金申报!</el-button>

    <el-dialog v-model="dialogVisible1" title="研一申报页面" width="30%">
      <el-button @click="reject" >奖学金申报</el-button>
      <el-button @click="dialogVisible1 = false">取消</el-button>

    </el-dialog>

    <el-dialog
        v-model="dialogVisible2" title="研二奖学金申报页面" width="30%">
      <el-form :model="form2" label-width="120px" :rules="rules">
        <el-form-item label="学位课总成绩">
          <el-input  style="width: 220px; height: 80%" v-model="form2.成绩"/>
        </el-form-item>
        <el-form-item label="学位课数量">
          <el-input-number v-model="form2.数量" :min="1" :max="100" @change="handleChange" />
        </el-form-item>
        <div>思政成绩</div>
        <el-form-item label="获得省级奖项次数">
            <el-input-number v-model="form2.思政成绩.获得省级奖项次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得市级奖项次数">
          <el-input-number v-model="form2.思政成绩.获得市级奖项次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得校级奖项次数">
          <el-input-number v-model="form2.思政成绩.获得校级奖项次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>

        <el-form-item label="导师组评价">
          <el-select v-model="form2.思政成绩.教师评价分" placeholder="导师组评价分">
            <el-option label="优秀" value="导师组评价优秀"/>
            <el-option label="良好" value="导师组评价良好"/>
          </el-select>
        </el-form-item>
        <el-form-item label="通报次数">
          <el-input-number  style="width: 220px" v-model="form2.通报次数" :min="0" :max="100" @change="handleChange"/>
        </el-form-item>
        <div>学术论文</div>
        <el-form-item label="获得 获得CCF推荐A类次数">
          <el-input-number v-model="form2.学术论文.一类次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得 获得CCF推荐B类次数">
          <el-input-number v-model="form2.学术论文.二类次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得 获得CCF推荐C类次数">
          <el-input-number v-model="form2.学术论文.三类次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="附件">
          <el-upload action="/api/files/upload" :on-success="filesUploadSuccess1">
            <el-button type="primary">上传</el-button>
<!--            <template #tip>-->
<!--              <div class="el-upload__tip">-->
<!--                jpg/png files with a size less than 500KB.-->
<!--              </div>-->
<!--            </template>-->
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible2 = false">取消</el-button>
        <el-button type="primary" @click="saveselect">申报</el-button>
      </span>
      </template>
    </el-dialog>

    <el-dialog
        v-model="dialogVisible3" title="研三奖学金申报页面" width="30%" >
      <el-form :model="form3" label-width="120px">
        <div>思政成绩</div>
        <el-form-item label="获得省级奖项次数">
          <el-input-number v-model="form3.思政成绩.获得省级奖项次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得市级奖项次数">
          <el-input-number v-model="form3.思政成绩.获得市级奖项次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得校级奖项次数">
          <el-input-number v-model="form3.思政成绩.获得校级奖项次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>

        <el-form-item label="导师组评价">
          <el-select v-model="form3.思政成绩.教师评价分" placeholder="导师组评价分">
            <el-option label="导师组评价优秀" value="导师组评价优秀"/>
            <el-option label="导师组评价良好" value="导师组评价良好"/>
          </el-select>
        </el-form-item>
        <div>学术论文</div>
        <el-form-item label="获得CCF推荐A类次数">
          <el-input-number v-model="form3.学术论文.一类次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得CCF推荐B类次数">
          <el-input-number v-model="form3.学术论文.二类次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>
        <el-form-item label="获得CCF推荐的C类次数">
          <el-input-number v-model="form3.学术论文.三类次数" :precision="0" :step="1" :min="0" :max="10" />
        </el-form-item>

      </el-form>
      <el-form-item label="附件">
        <el-upload action="/api/files/upload" :on-success="filesUploadSuccess2">
          <el-button type="primary">上传</el-button>
        </el-upload>
      </el-form-item>

      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible3 = false">取消</el-button>
        <el-button type="primary" @click="saveselect">申报</el-button>
      </span>
      </template>
    </el-dialog>




    </div>

</template>

<script>



import request from "../../utils/request"; //!!!!!!!
import Person from "@/views/Spersonal.vue";

export default {
  name: 'Student',
  components: {
  },
  data(){
    return{
      form:{},
      form1:{},
      form2:{
        "思政成绩":{},
        "学术论文":{},
      },
      form3:{
        "思政成绩":{},
        "学术论文":{},
      },
      dialogVisible1:false,
      dialogVisible2:false,
      dialogVisible3:false,
      search:'',
      tableData: [],
      grade:'',
      rules: {
        学位课数量: [
          { required: true, message: '请输入学位课数量', trigger: 'blur' },
          { validator: this.validateNumberNotZero, trigger: 'blur' }
        ]
      }


    }
  },
  created(){
    let str = sessionStorage.getItem("users")||"{}"
    this.person = JSON.parse(str)
    this.choose()
  },
  methods:{
    reject(){
      this.dialogVisible = false
      this.$message({type: "error", message: "研一由学院统一规定,暂时不可申请!"})
    },
    choose() {
      if (this.person.sgrade === "研一") {
        this.dialogVisible1 = true;
      } else if (this.person.sgrade === "研二") {
        this.dialogVisible2 = true;
      } else {
        this.dialogVisible3 = true;
      }
    },
    saveselect(){
      if(this.person.sgrade==="研二" ){
        this.form2["学号"] = this.person.sno;
        this.form2["姓名"] = this.person.sname;
        request.post("/student/g1", this.form2).then(res => {
          console.log(this.form2)
          console.log(this.res)
          this.$message({type: "success", message: "申请成功!"})
        })
      }
      else if(this.person.sgrade==="研三")
      {
        this.form3["学号"] = this.person.sno;
        this.form3["姓名"] = this.person.sname;
        request.post("/student/g2", this.form3).then(res => {
          console.log(this.form3)
          console.log(this.res)
          this.$message({type: "success", message: "申请成功!"})
        })
    }
      else{
        this.$message({type: "error", message: "研一由学院统一规定,暂时不可申请!"})

      }
      },
    validateNumberNotZero(rule, value, callback) {
      if (value === 0) {
        callback(new Error('学位课数量不能为0'));
      } else {
        callback();
      }
    },
    filesUploadSuccess1(res){
      console.log(res)
      this.form2["附件"]=res.data
    },
    filesUploadSuccess2(res){
      console.log(res)
      this.form3["附件"]=res.data
    }


  }
}
</script>
